package com.thread.async.future;

import java.util.concurrent.*;

/**
 * Created by zhuangqi on 17-6-17.
 */
public class FutureTask {

    private static Future<NettyTest.Netty> fn;

    public static void doTask(Callable<NettyTest.Netty> c ){

        ExecutorService es = Executors.newFixedThreadPool(2);

        //记得要用submit，执行Callable对象
        fn = es.submit(c);


    }

    public static void getResult(){
        //无限循环等待任务处理完毕  如果已经处理完毕 isDone返回true
        while (!fn.isDone()) {
            try {
                //处理完毕后返回的结果
                NettyTest.Netty nt = fn.get();
                System.out.println(nt.name);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

}
